﻿#region 文件信息

/*----------------------------------------------------------------
//
// 文件名称：
// 文件功能描述：
// 设计要求：
//
// 文 件 名：    VampirewalIoCRegisterAttribute
// 创建者：      杨程
// 创建日期：	    2022/12/14 17:15:30

//----------------------------------------------------------------*/

#endregion

namespace Vampirewal.Core.Attributes;

/// <summary>
/// 标记了这个特性的将会被框架扫描并添加进IoC容器
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class VampirewalIoCRegisterAttribute : Attribute
{
    /// <summary>
    /// 注册普通类
    /// </summary>
    /// <param name="token"></param>
    /// <param name="registerType"></param>
    public VampirewalIoCRegisterAttribute(string token, RegisterType registerType = RegisterType.Transient)
    {
        Token = token;
        this.RegisterType = registerType;
        Type = ClassType.Normal;
    }
    /// <summary>
    /// 注册服务
    /// </summary>
    /// <param name="interfaceType"></param>
    /// <param name="registerType"></param>
    public VampirewalIoCRegisterAttribute(Type interfaceType, RegisterType registerType = RegisterType.Singleton)
    {
        InterfaceType = interfaceType;
        Type = ClassType.Service;
    }

    /// <summary>
    /// 注册服务
    /// </summary>
    /// <param name="token"></param>
    /// <param name="classType"></param>
    /// <param name="registerType"></param>
    public VampirewalIoCRegisterAttribute(string token, ClassType classType, RegisterType registerType )
    {
        Token = token;
        this.RegisterType = registerType;
        Type = classType;
    }

    /// <summary>
    /// 全局唯一值
    /// </summary>
    public string Token { get; private set; }

    /// <summary>
    /// 注册模式
    /// </summary>
    public RegisterType RegisterType { get; private set; }

    /// <summary>
    /// 类型
    /// </summary>
    public ClassType Type { get; private set; }

    /// <summary>
    /// 接口类型
    /// </summary>
    public Type InterfaceType { get; private set; }
}

/// <summary>
/// 注册模式
/// </summary>
public enum RegisterType
{
    /// <summary>
    /// 单例生命周期注册
    /// </summary>
    Singleton,

    /// <summary>
    /// 瞬时生命周期注册
    /// </summary>
    Transient,

    /// <summary>
    /// 作用域生命周期注册
    /// </summary>
    Scoped
}

/// <summary>
/// 类的类型
/// </summary>
public enum ClassType
{
    /// <summary>
    /// 正常的
    /// </summary>
    Normal=0,
    /// <summary>
    /// 服务
    /// </summary>
    Service=1,

    /// <summary>
    /// 只注册到IOC
    /// </summary>
    NormalOnlyToIOC=2,
}